{{define "title"}}主页{{end}}{{define "contents"}}
<div class="container-fluid">
    <div class="panel panel-default">
        <div class="panel-heading">
            <span>用户信息</span>
        </div>
        <div class="panel-body">

        </div>
    </div>

    <div class="form-group" style="padding: 5px 0px;">
        <div class="input-group">
            <span class="input-group-addon">当前路径</span>
            <input class="form-control" name="path" id="path-content" value='{{.}}' />
        </div>
    </div>

    <div class="directory-list-header">
        <div class="row">
            <div class="col-md-7 col-sm-6 col-xs-10">文件</div>
            <div class="col-md-2 col-sm-2 col-xs-2 text-right">大小</div>
            <div class="col-md-3 col-sm-4 hidden-xs text-right">创建时间</div>
        </div>
    </div>

    <textarea id="list-template" style="display:none;">
        <li data-name="{server_filename}" data-href="?path={encoded_url_path}">
            <a href="?path={encoded_url_path}" class="clearfix" data-name="{server_filename}">
                <div class="row">
                    <span class="file-name col-md-7 col-sm-6 col-xs-9">
                        <i class="fa {fa_class} fa-fw"></i>
                        {server_filename} </span>
                    <span class="file-size col-md-2 col-sm-2 col-xs-3 text-right">
                        {size} </span>
                    <span class="col-md-3 col-sm-4 hidden-xs text-right">
                        {ctime} </span>
                </div>
            </a>
        </li>
    </textarea>

    <!-- 文件列表 -->
    <ul id="directory-listing" class="nav nav-pills nav-stacked">

    </ul>
</div>
{{end}}{{define "contents_js"}}
<script src="static/js/nano.js"></script>
<script>
    var formParam = $("#path-content").serialize();

    // 获取目录下的文件和目录列表
    $.ajax({
        type: "GET",
        url: "/cgi-bin/baidu/pcs/file/list",
        data: formParam,
        dataType: "json",
        success: function (result) {
            var dl = $("#directory-listing");
            
            var template = nano($("#list-template").val(), {
                encoded_url_path:escape("{{.}}".substring(0, "{{.}}".lastIndexOf("/"))),
                isdir           :true,
                fa_class        :"fa-folder",
                server_filename :"..",
                size            :0,
                ctime           :""
            });
            dl.append(template);
            
            for (k in result.list) {
                var ele = result.list[k];

                // uri编码
                ele.encoded_url_path = encodeURIComponent(ele.path);
                if (ele.isdir) {
                    ele.fa_class = "fa-folder";
                } else {
                    ele.fa_class = "fa-file";
                }

                ele.ctime = new Date(ele.ctime*1000).toLocaleString();

                var template = nano($("#list-template").val(), ele);

                dl.append(template);
            };
        },
    });

</script> {{end}}